package com.wsg.lightaccounting.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wsg.lightaccounting.Model.IncomeType;
import com.wsg.lightaccounting.Model.RecordManager;
import com.wsg.lightaccounting.R;

import java.util.List;

/**
 * Created by dell-pc on 2016/11/19.
 */

public class IncomeTypeAdapter extends BaseAdapter {
    private Context context;
    private List<IncomeType> icons;

    public IncomeTypeAdapter(Context context) {
        this.context = context;
        icons = RecordManager.incomeTypes;
    }

    @Override
    public int getCount() {
        return icons.size();
    }

    @Override
    public Object getItem(int position) {
        return icons.get(position);
    }

    @Override
    public long getItemId(int position) {
        return icons.get(position).getId();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ItemViewTag viewTag;

        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(context);
            convertView = inflater.inflate(R.layout.gridview_layout, null);
            viewTag = new ItemViewTag((ImageView) convertView.findViewById(R.id.grid_icon),(TextView) convertView.findViewById(R.id.grid_name));
            convertView.setTag(viewTag);
        }
        else {
            viewTag =(ItemViewTag) convertView.getTag();
        }
            viewTag.mName.setText(icons.get(position).getName());
//            switch (icons.get(position).getIcon()) {
//                case 0:
//                    viewTag.mIcon.setBackgroundResource(R.mipmap.btn_cancle_normal);
//                    break;
//                case 1:
//                    viewTag.mIcon.setBackgroundResource(R.drawable.btn_style_five_normal);
//                    break;
//                case 2:
//                    viewTag.mIcon.setBackgroundResource(R.drawable.btn_normal);
//                    break;
//                default:
//                    break;
//            }
        RecordManager.getRecordManager(context).setIcon(viewTag.mIcon,false,icons.get(position).getIcon());
        if (!icons.get(position).is_show())
        {
            convertView.setVisibility(View.GONE);
        }
        return convertView;
    }
    class ItemViewTag {
        protected ImageView mIcon;
        protected TextView mName;

        public ItemViewTag(ImageView icon, TextView name) {
            this.mName = name;
            this.mIcon = icon;
        }
    }
}
